package com.douqu.game.battle.route;

import com.douqu.game.battle.server.GameServer;
import com.douqu.game.core.util.LogUtils;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class RouteThread extends Thread
{
    public RouteQueue<RouteObject> queue;

    public RouteThread()
    {
        this.queue = new RouteQueue<>();
    }

    @Override
    public void run()
    {
        LogUtils.info("寻路线程开启----------->");

        while (GameServer.getInstance().isRunning()) {
            try {
                if (queue.isEmpty()) {
                    synchronized (queue) {
                        queue.wait();
                    }
                } else {
                    LogUtils.info("removeFirst");
                    RouteObject routeObject = queue.removeFirst();

                    routeObject.findRoute();
                }
            } catch (Exception e) {
                e.printStackTrace();
                LogUtils.error("寻路ERROR------------------->" + e);
                LogUtils.errorException(e);
            }
        }


        LogUtils.error("寻路线程挂了---------->");
    }





    public void addRouteObject(RouteObject routeObject)
    {
        queue.add(routeObject);
    }



}